package com.ruix.app.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by hadexs on 2017/4/13.
 */

public class RegUtil {

    // 数字格式验证
    public static boolean checkPhone(String phone) {
//		Pattern pattern = Pattern
//				.compile("^((13[0-9])|(15[^4,\\D])|(18[0,1,5-9]))\\d{8}$");
        Pattern pattern = Pattern
                .compile("^1\\d{10}$");
        Matcher matcher = pattern.matcher(phone);
        if (matcher.matches()) {
            return true;
        }
        return false;
    }
    public static Boolean isUserNameValid(String userName) {
        Boolean contentBoolean = false;
        Pattern pattern = Pattern.compile("^[0-9a-zA-Z_[\u4e00-\u9fa5]]{2,8}$");
        Matcher matcher = pattern.matcher(userName);
        contentBoolean = matcher.matches();
        if (!contentBoolean) {
            return contentBoolean;
        }
        String newString = userName.replaceAll("[[\u4e00-\u9fa5]]", "aa");
        if (newString.length() < 4 || newString.length() > 20) {
            return false;
        }
        return true;
    }

    public static Boolean isLessThanLength(String text,int length) {
        if (text.length() > length){
            return false;
        }
        String newString = text.replaceAll("[[\u4e00-\u9fa5]]", "aa");
        if (newString.length() < length) {
            return true;
        }
        return false;
    }

    public static Boolean isMoreThanLength(String text,int length) {
        if (text.length() > length){
            return true;
        }
        String newString = text.replaceAll("[[\u4e00-\u9fa5]]", "aa");
        return newString.length() > length;
    }
}
